
* Generate instrument non-response indicators for Sweep 3 outcomes

use "Data/NCDS/UKDA-5565-stata11/stata11/ncds0123.dta", clear
label variable n2411 "3P Hopes childs 1st job-job description"
label variable n2412 "3P Expect chlds 1st job - crtnty of ans"
label variable n2414 "3P Expect chlds 1st job-job description"


* Keep sweep 3 varaibles
qui ds, not(varl "ncdsid serial number"|varl "3* *")
drop `r(varlist)'

* code all non-response as -1
qui ds, not(varl "ncdsid serial number")
foreach name of varlist `r(varlist)'{
qui replace `name'=-1 if `name'<-1
qui su `name'
qui replace `name'=-1 if `name'==`r(min)' & `r(min)'>=0
}

* find obs with all non-response in instrument
local Labs 3S 3I 3P 3T
foreach d of local Labs{
qui ds ,has(varl "`d' *")
egen equalminus1=anycount(`r(varlist)'), values(-1)
qui ds ,has(varl "`d' *")
egen equalmiss=rowmiss(`r(varlist)')
qui ds ,has(varl "`d' *")
egen equalnomiss=rownonmiss(`r(varlist)')
ge numvars= equalmiss+equalnomiss
ge nummis=equalmiss+equalminus1
ge Obs_`d'=1-(nummis==numvars)
drop equal* numvars nummis
}

********************************************************************************
* Finish up
********************************************************************************

rename Obs_3* Obs_*16 
keep ncdsid Obs*
rename ncdsid NCDSID
sort NCDSID

save scratchdata/ncds_Sweep3Obs.dta, replace
